package com.manhanlou.service;

import com.manhanlou.dao.EmployeeDao;
import com.manhanlou.domain.Employee;
import com.manhanlou.utils.DruidUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 业务层:完成对Employee的各种操作--通过调用EmployeeDao完成
 *
 * @author wty
 * @date 2022/11/9 10:07
 */
public class EmployeeService {
    /**
     * 调用EmployeeDao完成各种操作
     */
    private EmployeeDao employeeDao = new EmployeeDao();

    /**
     * 根据empId和pwd返回一个Employee对象
     * 如果查询不到，就返回空
     *
     * @param
     * @return com.manhanlou.domain.Employee
     * @param: empId
     * @param: pwd
     * @date 2022/11/9 10:10
     * @author wty
     **/
    public Employee getEmployeeByEmpidAndPwd(String empId, String pwd) {
        Employee employee = null;

        String sqlStr = "select id,empId,pwd,name,job from employee where empId = ? and pwd = md5(?)";

        employee = employeeDao.querySingle(sqlStr, Employee.class, empId, pwd);

        return employee;
    }

    public List<Employee> getEmployeeInfo() {
        List<Employee> list = new ArrayList<>();

        String sqlStr = "SELECT empid,NAME,job FROM employee";

        list = employeeDao.queryMulti(sqlStr, Employee.class);

        return list;
    }
}
